package net.m510.autosurfer.aeoncard;

import java.util.logging.Logger;

import net.m510.autosurfer.common.exception.CannotLoginException;
import net.m510.autosurfer.core.DocumentChecker;
import net.m510.autosurfer.core.exception.UserProcessException;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class AeonCardLoginChecker implements DocumentChecker {
	private static final Logger log = Logger.getLogger(AeonCardLoginChecker.class.getName());

	@Override
	public void check(Document doc) throws UserProcessException {
		String title = doc.head().select("title").first().text();
		// ログインエラーチェック
		log.fine( title );
		if ( title.contains("ログイン認証エラー") ) {
			Element e = doc.getElementById("aeon2010mainArea");
			CannotLoginException ex = new CannotLoginException(e.text());
			ex.setDocument(doc);
			throw ex;
		}
		if ( title.contains("ＭｙＰａｇｅログイン") ) {
			CannotLoginException ex = new CannotLoginException("ログインページに戻ってきたようです");
			ex.setDocument(doc);
			throw ex;
		}
		
	}

}
